package com.example.skycode6.util;

import java.sql.Connection;
import java.sql.DriverManager;

public class DBConnection {
    private String FileName;
    private int DBType;
    private Connection conn;
    private String MysqlDriver;
    private String MysqlURL;

    public DBConnection() {
        conn = null;
    }

    // 根据数据库类型创建数据库连接，此处默认类型为1：mysql
    public Connection getConn() {

        DBType = 1;

        switch (DBType) {
            case 1:
                return (getConnToMysql());
            default:
                return null;
        }
    }

    // 创建数据库连接
    public Connection getConnToMysql() {
        try {
            MysqlDriver = "com.mysql.cj.jdbc.Driver";
            MysqlURL = "jdbc:mysql://localhost:3306/sky_gjh?" + "user=root&password=mysql123456" + "useUnicode=true&characterEncoding=UTF-8";
            Class.forName(MysqlDriver).newInstance();
            conn = DriverManager.getConnection(MysqlURL);
        } catch (Exception e) {
        }
        return conn;
    }
}
